home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 03 / 7 / DISK0378.ZIP / TALLY.DOC < prev    next >
Text File  |  1994-10-26  |  6KB  |  157 lines

  1.     TALLY.EXE                            Page 1
  2.     
  3.     
  4.     TALLY.EXE is a utility program which counts the number of characters,
  5.     words, and lines in an input file.  It mirrors the function of WC.EXE
  6.     that is included on a number of the larger bulletin boards and also
  7.     mirrors the UNIX WC function.  I don't know who authored the WC.EXE
  8.     program that I have or whether it is the most current release.  The
  9.     source that I fiddled with came from Kernighan and Ritchie.
  10.     
  11.     
  12.     WHY ANOTHER VERSION?
  13.     
  14.     1)  WC.EXE returns in incorrect character count for text files, as 
  15.     discussed below under "COMPARISON OF WC.EXE AND TALLY.EXE".
  16.     
  17.     2)  WC.EXE was compiled with the C-86 compiler from Computer
  18.     Innovations.  TALLY.EXE, written with Mark DeSmet's package, seems to
  19.     produce a smaller, faster program:  
  20.     
  21.         a)  WC.EXE, for example, is about 14,000 characters;  TALLY
  22.         is about 11,000.  I don't know how WC was compiled, so I 
  23.         can't tell why it's smaller, and I'm not claiming any 
  24.         advantage for DeSmet.
  25.     
  26.         b)  Benchmark timing for a large file (43,500 characters) was
  27.         54 seconds for WC.EXE and 20 seconds for TALLY, about three 
  28.         times faster, at least for this application.  
  29.     
  30.     
  31.     TO USE TALLY:  
  32.     
  33.     The file you examine should be a text file for results to be
  34.     meaningful, but TALLY will still produce a listing for machine code
  35.     files without complaint.  Invoke the program with the following
  36.     command:
  37.     
  38.             TALLY filespec
  39.     
  40.     where filespec is the name of any TEXT(!) file.  TALLY will return a
  41.     count of:
  42.     
  43.         The number of lines in your input file, including blank
  44.         lines.  I considered excluding blank lines from the count,
  45.         but it seems to me that the number of printer lines would
  46.         more often be useful.
  47.     
  48.         The number of words, defined as blank delimited strings. 
  49.         Something I'm not sure about is special characters that
  50.         might be used by text editors and word processors for "soft
  51.         returns".  I don't think they should appear in an ASCII
  52.         file, but I can't be certain.  Please let me know if I'm
  53.         wrong.
  54.     îTALLY.EXE                            Page 2
  55.     
  56.     
  57.     
  58.         The number of text characters in your file, excluding
  59.         blanks, carriage returns, linefeeds, tabs, and EOF.  (Hex
  60.         values 20, 0D, 0A, 09, and 1A, respectively.)  
  61.     
  62.         The total number of characters in the file, equal to the
  63.         number returned by the DOS DIR command.
  64.     
  65.     
  66.     COMPARISON OF WC.EXE AND TALLY.EXE:  
  67.     
  68.     The first version of TALLY generated some comment on Gene Plantz's
  69.     bulletin board that WC and TALLY produced different results.  In
  70.     checking  it out, I fixed two bugs I didn't see during testing (word
  71.     and line counts were high by 1) and made some cosmetic changes (see
  72.     below).  To test the two programs, I built the following file with
  73.     EDIX, consisting of 4 lines of "test test test test", resulting in:
  74.     
  75.         test test test test test
  76.         test test test test test
  77.         test test test test test
  78.         test test test test test
  79.     
  80.     Looking at the file with DEBUG or Norton's DISKLOOK, you'll see:
  81.     
  82.         test/test/test/test/test<^
  83.         test/test/test/test/test<^
  84.         test/test/test/test/test<^
  85.         test/test/test/test/test<^
  86.         !
  87.     
  88.     Special characters are supplied for illustration only, where: 
  89.         
  90.         < represents a carriage return     (13 Ascii, 0d Hex),
  91.         ^ represents a linefeed        (10 Ascii, 0a Hex),
  92.         ! represents an EOF character    (26 Ascii, 1a Hex), and
  93.         / represents a blank        (32 Ascii, 20 Hex).
  94.     
  95.     The EOF character may or may not be present in your file, depending
  96.     on how you create it.  If you COPY CON: TEST.TXT, and close it with a
  97.     CTRL/Z, it will terminate with Hex 00.  This version of TALLY
  98.     accounts for both types of text file and will produce the same result
  99.     regardless of method.  
  100.     TALLY.EXE generates this output:
  101.     
  102.     TALLY for test.txt --
  103.     
  104.     -- 5 lines, 20 words, 80 text characters, and 105 total characters.
  105.     
  106.     -- Text excludes blank, return, linefeed, tab, and EOF characters.
  107.     
  108.     -- Line count totals all lines, including blank lines.
  109.     îTALLY.EXE                            Page 3
  110.     
  111.     
  112.     WC.EXE produces this output for the same file:
  113.     
  114.     Characters = 100, words = 20, lines = 4.
  115.     
  116.     
  117.     The differences are:
  118.     
  119.         1) WC appears to count spaces as text characters and
  120.         excludes either carriage returns or linefeed characters. I
  121.         treat all three as "white space" characters in TALLY. 
  122.     
  123.         2) Tally supplies a separate grand total of all characters,
  124.         agreeing with the DOS directory filesize.
  125.         
  126.         3) If your file exceeds 32,767 characters, WC goes
  127.         negative, since it defines its character counter as a
  128.         simple integer.  Same problem as in Basic.  TALLY defines
  129.         the counter as an unsigned integer, accurate to 65,536
  130.         characters.
  131.     
  132.         4) WC undercounts the number of lines in the file by one.
  133.         (So did my first version.)  TALLY counts the number of
  134.         linefeeds in the file ('\n' characters in "C").  If your
  135.         file terminates with a carriage return/linefeed/EOF
  136.         combination, it will generate a print line if you TYPE or
  137.         print the file, so I count it.  If not, I don't.
  138.     
  139.     
  140.     TALLY is very simple in concept and operation, but it may come in
  141.     handy.  TALLY.EXE is a public domain utility; you may freely share 
  142.     it with anyone you choose.  I hope you find it helpful.
  143.     
  144.     Comments and suggestions for improvement of the program are welcome. 
  145.     Thanks to those who commented on the earlier version.
  146.     
  147.                             April 15, 1984
  148.     
  149.                             Jon Sims
  150.                             600 C South Blvd.
  151.                             Evanston, Il 60202 î
  152. April 15, 1984
  153.     
  154.                             Jon Sims
  155.                             600 C South Blvd.
  156.                             Evanston, Il 60202 î
  157.